#ifndef _DevicesIFRP_H_
#define _DevicesIFRP_H_

#define IFRP_DECODE_LOW_MIN    (560 * 2 - 280)
#define IFRP_DECODE_LOW_MAX    (560 * 2 + 280)

#define IFRP_DECODE_HIGH_MIN   (560 * 4 - 280)
#define IFRP_DECODE_HIGH_MAX   (560 * 4 + 280)

#define IFRP_DECODE_HEAD_MIN   (560 * 24 - 280)
#define IFRP_DECODE_HEAD_MAX   (560 * 24 + 280)

#define IFRP_DECODE_REPEAT_MIN (560 * 20 - 280)
#define IFRP_DECODE_REPEAT_MAX (560 * 20 + 280)



typedef enum {
    IFPRIdle = 0,

    IFPRStart,
    IFPRStartLow,

    IFPRStop,

    IFPRRepeat,
    IFPRRepeatLow,
    IFPRRepeatEnd,

    IFPRLogical1,
    IFPRLogical1Low,

    IFPRLogical0,
    IFPRLogical0Low,
}IFRPEncodeStateEnum;



typedef enum{
    necReset = 0,
    necSucceed,
    necRepeat,

    necReadUser,
    necReadControl,
    necReadData,

    necMode0,
    necMode1,
    necControl,
    necData,
    necCrc,
}IFRPStateEnum;


typedef struct{
    int8_t state;
    int8_t length;
    uint8_t user;
    uint8_t control;
    uint32_t data;

    uint8_t mode0;
    uint8_t mode1;
    uint8_t datas[9];
    uint8_t crc;

    uint16_t timeNow;
    uint16_t timeClock[7];
}IFRPCodeType;





extern IFRPCodeType g_typeIFRPDecode;




void vIFRPInit(void);

void vIFRPEncodeInit(void);
int8_t cIFRPEncodeSendDatas(uint8_t *pucDatas, int32_t iLength);
void vIFRPEncodeMachine(void);

void vIFRPDecodeInit(void);
int8_t cIFRPDecode(IFRPCodeType *ptypeData, int16_t sValue);

#endif
